<?php
namespace zzcms\primary\controller;


class Slide extends Base
{
    protected $model;

    protected function initialize()
    {
        parent::initialize();
        $this->model = new \zzcms\admin\model\Poster();
    }

    public function index()
    {
        $id = isset($this->info['id']) ? max(intval($this->info['id']), 1) : 1;
        $poster_cache = getCache('poster');
        $lists = [];
        foreach ($poster_cache as $k => $item) {
            if ($item['space_id'] == $id) {
                $item['image'] = $this->base_image_url . $item['thumb'];
                $lists[] = $item;
            }
        }
        $this->array2json(['code' => 0, 'data' => $lists]);
    }

    /**
     * 今日头条
     */
    public function headlines()
    {
        $model = new \zzcms\common\model\News();
        $where = [];
        $where[] = ['status', '=', 1];
        $lists = $model->getList(['where' => $where, 'order' => 'listorder desc', 'limit' => 6, 'field' => 'id,meta_title']);
        foreach ($lists as $k => $item) {
            $item['url'] = '/pages/news/detail/detail?id=' . $item['id'];
            $lists[$k] = $item;
        }
        $this->array2json(['code' => 0, 'data' => $lists]);
    }

}
